package com.finalab.website.interceptor;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
public class EncodingInterceptor extends HandlerInterceptorAdapter {


	private final String ENCODING = "utf-8";
	
	private String[] needNotEncodingUrl = {};
	
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
	{
		String requestUrl = request.getRequestURI();
		for(String url : needNotEncodingUrl) {
			if(requestUrl.startsWith(url)) {
				return true;
			}
		}
		try
		{
			request.setCharacterEncoding(ENCODING);
			response.setCharacterEncoding(ENCODING);
		}
		catch (Exception e)
		{
			e.printStackTrace();
			return false;
		}
		return true;
	}
	
}
